const path = require("path");
const webpack = require("webpack");

const PROJECT_ROOT = path.resolve(__dirname, "..");
const commonConfig = {
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: "ts-loader",
        exclude: /node_modules/,
      },
      {
        test: /\.css$/i,
        use: ["style-loader", "css-loader", "postcss-loader"],
      },
    ],
  },
  resolve: {
    alias: {
      "@": path.join(PROJECT_ROOT),
      "@shadcn": path.join(PROJECT_ROOT, "./shadcn/components/ui"),
      "@common": path.join(PROJECT_ROOT, "../cdp-test/common"),
    },
    extensions: [".tsx", ".ts", ".js"],
  },
  plugins: [
    new webpack.DefinePlugin({
      "process.env.BACKEND_HOST": JSON.stringify(
        process.env.BACKEND_HOST
          ? process.env.BACKEND_HOST
          : "https://www.anmesa.com",
      ),
    }),
  ],
};

module.exports = {
  PROJECT_ROOT,
  commonConfig,
};
